<template>
	<view class="wrap" :style="{ height: this.app_height * 2 + 'rpx' }">
		<view class="comment" v-for="(res, index) in commentList">
			<view class="right">
				<view style="display: flex;margin-left: 15rpx;margin-top: 15rpx;">
					<u-avatar  :src="res.userPic"></u-avatar>
					<!-- @click="userinfo(res)" -->
					<view style="flex: 1;margin-left: 20rpx;display: flex;flex-direction: column;">
						<view style="    display: flex;     align-items: center;">
							{{res.userName}}

						</view>
						<view v-if="res.age != null">
							<text v-if="res.sex == 'F'" style="">
								女 · 
							</text>
							<text v-if="res.sex == 'M'" style="">
								男 · 
							</text>  {{ res.age}}岁
						</view>
						<view style="display: flex;">
							<view>{{res.pubDate}}</view>
						</view>
					</view>
					<view class="gd" style="margin-left: auto;">
						<view class="image" style="width: 50rpx;height: 50rpx;margin-left: 20rpx;">
							<image src="../../static/userinput-gd.png" style="width: 100%; height: 100%;" mode="" />
						</view>
					</view>

				</view>
				<!-- 文本内容 -->
				<view class="content">
					{{res.content}}
				</view>
				<!-- 图片显示区域 -->
				<view class="reply-box" v-if="res.pics.length != 0">
					<view v-if="res.pics.length == 1"
						style="padding: 20rpx;display: flex;justify-content: space-between;flex-wrap: wrap;">
						<image @click="previewImage(index1,res.pics)" v-for="(res1, index1) in res.pics" :src="res1"
							mode="aspectFill" style="width: 100%;"></image>
					</view>
					<view v-if="res.pics.length == 2 || res.pics.length == 4"
						style="padding: 20rpx;display: flex;justify-content: space-between;flex-wrap: wrap;">
						<image @click="previewImage(index1,res.pics)" v-for="(res1, index1) in res.pics" :src="res1"
							mode="aspectFill" style="width:334rpx;height:334rpx;margin-bottom: 10rpx;"></image>
					</view>
					<view v-if="res.pics.length == 3 || res.pics.length == 6 || res.pics.length == 7"
						style="padding: 20rpx;display: flex;justify-content: space-between;flex-wrap: wrap;">
						<image @click="previewImage(index1,res.pics)" v-for="(res1, index1) in res.pics" :src="res1"
							mode="aspectFill" style="width:220rpx;height:220rpx;margin-bottom: 10rpx;"></image>
					</view>
					<view v-if="res.pics.length == 5 || res.pics.length == 8"
						style="padding: 20rpx;display: flex;justify-content: space-between;flex-wrap: wrap;">
						<image @click="previewImage(index1,res.pics)" v-for="(res1, index1) in res.pics" :src="res1"
							mode="aspectFill" style="width:220rpx;height:220rpx;margin-bottom: 10rpx;"></image>
						<view style="width:220rpx;height:220rpx;"></view>
					</view>
					<view v-if="res.pics.length == 9" 11
						style="padding: 20rpx;display: flex;justify-content: space-between;flex-wrap: wrap;">
						<image @click="previewImage(index1,res.pics)" v-for="(res1, index1) in res.pics" :src="res1"
							mode="aspectFill" style="margin-bottom: 10rpx;width:220rpx;height:220rpx;"></image>
					</view>
					<view style="display: flex;justify-content: space-between;">
						<view>获得的点赞数:{{res.likeNum}}</view>
						<view class="like" @click="shanchu(res.id)">
							<!-- shanchu(res.id), -->
							删除
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as api from '@/api/api.js'
	export default {
		data() {
			return {
				u_id: '',
				scrollTop: 0,
				commentList: "",
				show: false,
				t_id: '',
				content: '您确认要删除该内容吗？',
				app_height: 0
			}
		},
		onLoad(res) {
			//获取动态列表
			this.u_id = res.id;
			this.getComment();
			const _this = this;
			uni.getSystemInfo({
				success: res => {
					console.log('手机可用高度:' + res.windowHeight * 2 + 'rpx');
					_this.app_height = res.windowHeight * 2;
				}
			});
		},
		onShow() {
			//this.getComment();
		},
		onPullDownRefresh: function() {
			this.getComment();
		},
		//返回顶层
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			//删除圈子
			shanchu(id) {
				var that = this
				uni.showModal({
				    title: this.invitatioCode,
				    content: '您确认要删除该内容吗？',
				    success: function (res) {
				        if (res.confirm) {
				            console.log('用户点击确定');
							let arr = []
							arr.push(id)
							api.request({
								url: '/p/post-record',
								method: 'DELETE',
								data: [id],
							}).then(res => {
								console.log(res);
							})
							uni.switchTab({
								url:'/pages/user/user'
							})
							that.getComment();
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				console.log(id);
			},
			//跳转个人中心
			userinfo(res) {
				//console.log(res)
				uni.navigateTo({
					url: '../user/userinfo/userinfo?uid=' + res.uid
				})
			},
			//跳转评论详情
			comment(res) {
				//console.log(res);
				uni.navigateTo({
					url: './comment?id=' + res.id
				})
			},
			//图片预览
			previewImage(current, photos) {
				uni.previewImage({
					current,
					urls: photos
				})
			},
			//信息初始化
			getComment() {
				uni.showLoading({
					title: '加载中'
				})
				api.request({
					url: '/p/post-record/one/page',
					method: 'GET',
					data: {},
				}).then(res => {
					for (let item in res.data.records) {
						res.data.records[item].pics = res.data.records[item].pics.split(',')
					}
					this.commentList = res.data.records
					console.log(this.commentList);
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #242329;
	}

	.wrap {
		width: 100%;
		height: 100%;
		background-color: #242329;
	}
	
	.like {
		font-size: 32rpx;
		text-align: center;
		color: #ffffff;
		width: 150rpx;
		height: 60rpx;
		background-color: red;
		border-radius: 30rpx;
		line-height: 60rpx;
		margin-right: 30rpx;
	}
	
	.comment {
		background: #242329;
		display: flex;
		border-radius: 20rpx;
		//padding: 30rpx;
		//margin-top: 10rpx;
		margin-bottom: 20rpx;
		margin-left: 15rpx;
		margin-right: 15rpx;
		color: #FFFFFF;

		.grid-text {
			font-size: 28rpx;
			margin-top: 4rpx;
			color: #FFFFFF;
		}

		.pic {
			.img_wrapper {
				width: 220upx;
				height: 150upx;
				margin-right: 15upx;
				display: inline-block;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.left {
			image {
				width: 64rpx;
				height: 64rpx;
				border-radius: 50%;
				background-color: #242329;
			}
		}
		
		
		.right {
			flex: 1;
			//padding-left: 20rpx;
			font-size: 30rpx;

			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10rpx;

				.name {
					position: absolute;
					left: 110rpx;

				}

				

				.highlight {
					color: #5677fc;

					.num {
						color: #5677fc;
					}
				}
			}

			.content {
				//margin-bottom: 10rpx;
				margin-left: 20rpx;
				margin-top: 15rpx;
				margin-bottom: 15rpx;
			}

			.reply-box {
				//background-color: rgb(242, 242, 242);
				//border-radius: 12rpx;

				.item {
					padding: 20rpx;
					border-bottom: solid 2rpx $u-border-color;

					.username {
						font-size: 24rpx;
						color: #fff;
					}
				}

				.all-reply {
					padding: 20rpx;
					display: flex;
					color: #5677fc;
					align-items: center;

					.more {
						margin-left: 6rpx;
					}
				}
			}

			.test {
				float: left;
				padding: 15rpx;
			}

			.img {
				display: flex;
			}

			.bottom {
				//margin-top: 20rpx;
				// margin-left: 10rpx;
				// display: flex;
				// font-size: 24rpx;
				// color: #9a9a9a;
				// margin-bottom: 10rpx;

				.reply {
					color: #5677fc;
					margin-left: 10rpx;
				}

				.weibo-handle {
					display: flex;
					//padding-top: 15rpx;
					font-size: 28rpx;
					padding-bottom: 25rpx;
				}

				.weibo-handle image {
					width: 50rpx;
					height: 50rpx;
					margin-right: 20rpx;
				}

				.weibo-handle view {
					flex: 1;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.weibo-handle .comment-group {
					background: #242329;
				}

				.weibo-handle .praise-group {
					background: #242329;
				}
			}
		}
	}
</style>
